var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r, s = t("GlobalUserData"),
l = t("GameConstant"),
c = t("HallConstant"),
d = t("HallScene"),
h = t("BroadCastMessage"),
p = t("Util"),
u = t("Bounce"),
f = t("Particle"),
m = t("Global"),
_ = t("StorageManager"),
y = t("BaseStorage"),
g = cc._decorator,
v = g.ccclass,
C = g.property; (function(t) {
    t[t.unkonwn = 0] = "unkonwn",
    t[t.gold = 1] = "gold",
    t[t.diamond = 2] = "diamond",
    t[t.power = 3] = "power"
})(r || (r = {}));
var b = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.statusLabel = null,
        e.timeSlot = {
            startTime: 0,
            endTime: 0
        },
        e._value = 0,
        e.obj = {
            a: 0
        },
        e.value = 0,
        e.giftType = r.unkonwn,
        e.iconFrame = null,
        e.normalBtn = null,
        e.iconSpr = null,
        e.videoBtn = null,
        e.valueLabel = null,
        e.receiveBtn = null,
        e.goldPrefab = null,
        e.statusText = null,
        e.frames = [],
        e.mask = null,
        e.toggle = null,
        e
    }
    return n(e, t),
    e.prototype.onLoad = function() {
        this.mask.active = !1,
        this._storageKey = m.BaseStorageKey.Receive + this.node.name,
        _.StorageManager.setDailyTaskStorageKey(this._storageKey)
    },
    e.prototype.onEnable = function() {
        this.node.scale = 0,
        cc.tween(this.node).to(.5, {
            scale: 1
        },
        {
            easing: "elasticOut"
        }).start()
    },
    e.prototype.start = function() {
        switch (this.iconSpr.spriteFrame = this.iconFrame, this.node.name) {
            case "am":
                this.timeSlot.startTime = s.default.nDepotTime.am.star,
            this.timeSlot.endTime = s.default.nDepotTime.am.end;
            break;
            case "pm":
                this.timeSlot.startTime = s.default.nDepotTime.pm.star,
            this.timeSlot.endTime = s.default.nDepotTime.pm.end;
            break;
            case "ev":
                this.timeSlot.startTime = s.default.nDepotTime.ev.star,
            this.timeSlot.endTime = s.default.nDepotTime.ev.end;
        }
        this.Value = 6 * this.value,
        this.refreshTime(),
        this.schedule(this.refreshTime, .5),
        s.default.bAuditMode && (this.videoBtn.active = !1, this.normalBtn.active = !0, this.toggle.isChecked = !1)
    },
    e.prototype.Toggle = function(t) {
        this.expression(t.isChecked)
    },
    e.prototype.expression = function(t) {
        this.videoBtn.active = t,
        this.normalBtn.active = !t,
        this.Value = t ? 6 * this.value: this.value
    },
    e.prototype.refreshTime = function() {
        this.getTimeNow() < this.timeSlot.startTime ? (this.receiveBtn.node.parent.active = !1, this.statusText.spriteFrame = this.frames[2]) : this.getTimeNow() > this.timeSlot.endTime ? (this.receiveBtn.node.parent.active = !1, this.getReceiveStatus() ? this.statusText.spriteFrame = this.frames[0] : (this.mask.active = !0, this.statusText.spriteFrame = this.frames[1])) : this.getReceiveStatus() ? (this.receiveBtn.node.parent.active = !1, this.statusText.spriteFrame = this.frames[0]) : (p.Util.videoExposure(m.VideoTab.dim15), this.receiveBtn.node.parent.active = !0),
        this.statusText.node.active = !this.receiveBtn.node.parent.active
    },
    e.prototype.receive = function() {
        h.default.getInstance().SendMessage(c.Broadcast_Func.Audio, c.Audio_ID.btn_click),
        this.videoBtn.active ? p.Util.showRewardVideo(this.getGift.bind(this)) : this.getGift()
    },
    e.prototype.getGift = function() {
        switch (y.BaseStorage.setString(this._storageKey, "1"), this.giftType) {
            case r.diamond:
                this.action("frame_diamond"),
            s.default.saveDiamondData(!0, this.Value),
            cc.find("Canvas").getComponent(d.default).onSetOwnDiamond(!0);
            break;
            case r.gold:
                this.action("frame_gold"),
            s.default.saveGoldData(!0, this.Value),
            cc.find("Canvas").getComponent(d.default).onSetOwnGold(!0);
            break;
            case r.power:
                this.action("frame_vit"),
            s.default.saveVitData(!0, this.Value),
            cc.find("Canvas").getComponent(d.default).onSetOwnVit(!0);
        }
    },
    e.prototype.action = function(t) {
        h.default.getInstance().SendMessage(l.Game_Broadcast_Func.Audio, c.Audio_ID.get_gold);
        for (var e = 0; e < 20; e++) {
            var o = cc.instantiate(this.goldPrefab),
            i = cc.find("Canvas").getChildByName(t).convertToWorldSpaceAR(cc.Vec2.ZERO),
            n = this.node.convertToNodeSpaceAR(i),
            a = this.node.getChildByName("giftBg").getPosition();
            o.setPosition(a),
            o.parent = this.node,
            o.getComponent(f.default).init(p.Util.getRandomInt(0, 360), p.Util.getRandomInt(200, 400), n, this.iconFrame)
        }
    },
    Object.defineProperty(e.prototype, "Value", {
        get: function() {
            return this._value
        },
        set: function(t) {
            this.valueLabel.node.addComponent(u.default).init(1, t),
            this._value = t
        },
        enumerable: !1,
        configurable: !0
    }),
    e.prototype.getReceiveStatus = function() {
        return "1" == y.BaseStorage.getString(this._storageKey)
    },
    e.prototype.getTimeNow = function() {
        return new Date().getHours()
    },
    e.prototype.getDateString = function() {
        return new Date().toDateString()
    },
    a([C(cc.Float)], e.prototype, "value", void 0),
    a([C({
        type: cc.Enum(r)
    })], e.prototype, "giftType", void 0),
    a([C(cc.SpriteFrame)], e.prototype, "iconFrame", void 0),
    a([C(cc.Node)], e.prototype, "normalBtn", void 0),
    a([C(cc.Sprite)], e.prototype, "iconSpr", void 0),
    a([C(cc.Node)], e.prototype, "videoBtn", void 0),
    a([C(cc.Label)], e.prototype, "valueLabel", void 0),
    a([C(cc.Button)], e.prototype, "receiveBtn", void 0),
    a([C(cc.Prefab)], e.prototype, "goldPrefab", void 0),
    a([C(cc.Sprite)], e.prototype, "statusText", void 0),
    a([C([cc.SpriteFrame])], e.prototype, "frames", void 0),
    a([C(cc.Node)], e.prototype, "mask", void 0),
    a([C(cc.Toggle)], e.prototype, "toggle", void 0),
    a([v], e)
} (cc.Component);
o.default = b